package redis.Impl;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import redis.IRedisService;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author caosinuo
 * @date 2019/5/22 10:23
 */
public class RedisService implements IRedisService {

   @Resource
   private RedisTemplate redisTemplate;


   @Override
   public void setKey(String key, String value) {
      ValueOperations<String, String> ops = redisTemplate.opsForValue();
      ops.set(key, value, 900, TimeUnit.SECONDS);//15分钟过期

   }

   @Override
   public String getValue(String key) {
      ValueOperations<String, String> ops = redisTemplate.opsForValue();
      return ops.get(key);
   }

   @Override
   public void delete(String key) {
      redisTemplate.delete(key);
   }
}
